﻿using System;

namespace Csharp重载运算符
{
    struct Vector2
    {
        public int x, y;
        public Vector2(int x, int y) 
        {
            this.x = x;
            this.y = y;
        }

        public override string ToString()
        {
            return string.Format("({0},{1})",x,y);
        }

        public static bool operator == (Vector2 a, Vector2 b)
        {
            return (a.x == b.x) && (b.x == b.y);
        }

        public static bool operator !=(Vector2 a, Vector2 b)
        {
            return !(a==b);
        }

        //重载加法,加法里面有两个参数
        public static Vector2 operator +(Vector2 a, Vector2 b) 
        {
            Vector2 result = new Vector2(a.x + b.x,a.y+b.y);
            return result;
        }
    }
    class Program
    {
        static void Main(string[] args)
        {
            Vector2 pointA = new Vector2(1, 1);

            Vector2 pointB = new Vector2(2, 2);

            Vector2 Add = pointA + pointB;

            Console.WriteLine(Add);

        }
    }
}
